package org.lai.mapper;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.lai.pojo.Student;
import org.lai.pojo.StudentQueryParm;

import java.util.List;
import java.util.Map;

@Mapper
public interface StudentMapper {
    /**
     * 分页查询
     * @param student
     * @return
     */
    public List<Student> getList(StudentQueryParm student);

    /**
     * 新增学员
     * @param student
     */
    void insert(Student student);

    Student getById(Integer id);

    void update(Student student);
    @Delete("delete from student where id = #{id}")
    void deleteById(Integer id);
    @Update("update student set violation_count = violation_count + 1, violation_score = violation_score + #{score} where id = #{id}")
    void updateScore(Integer id, Integer score);

    @Select("select c.name clazzList,count(*) dataList from student left join clazz c on student.clazz_id = c.id group by c.name order by dataList desc ;")
    List<Map<String, Object>> getStudentCountData();
    @Select("select\n" +
            "     (case s.degree when 1 then '初中'\n" +
            "         when 2 then '高中'\n" +
            "             when 3 then '大专'\n" +
            "                     when 4 then '本科'\n" +
            "                         when 5 then '硕士'\n" +
            "                             when 6 then '博士'\n" +
            "                                 else '其他' end ) name\n" +
            "     ,count(*) value from student s group by degree order by count(*) desc ;")
    List<Map<String, Object>> getStudentDegreeData();
}
